import 'package:flutter/material.dart';

class NewsTimeView extends StatelessWidget {
  const NewsTimeView({super.key});

  @override
  Widget build(BuildContext context) {
    String strTime0 =
        '今天 ${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}:${DateTime.now().second.toString().padLeft(2, '0')}';

    return SizedBox(
      height: 48,
      child: Row(
        children: [
          const SizedBox(
            width: 17,
          ),
          Container(
              height: 24,
              width: 24,
              decoration: const BoxDecoration(
                  color: Color(0xFFFFFFFF),
                  borderRadius: BorderRadius.all(Radius.circular(5.0)),
                  boxShadow: [
                    BoxShadow(
                        blurRadius: 4,
                        offset: Offset(0, 2),
                        color: Color(0x1A2B3039))
                  ]),
              child: Wrap(
                children: [
                  Container(
                    height: 8,
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.vertical(
                            top: Radius.circular(4)),
                        color: const Color(0xFFFE7241).withOpacity(0.8)),
                  ),
                  Center(
                    child: Text(DateTime.now().day.toString().padLeft(2, '0'),
                        style: const TextStyle(
                          fontSize: 13,
                          color: Color(0xFF2B3039),
                          height: 1.3,
                          fontWeight: FontWeight.w500,
                        )),
                  ),
                ],
              )),
          const SizedBox(
            width: 15,
          ),
          StreamBuilder<String?>(
              initialData: strTime0,
              stream: Stream.periodic(const Duration(seconds: 1), (value) {
                var time = DateTime.now();

                String strTime =
                    '今天 ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}:${time.second.toString().padLeft(2, '0')}';

                return strTime;
              }),
              builder: (context, AsyncSnapshot<String?> snapshot) {
                return Text(
                  '${snapshot.data}',
                  style: const TextStyle(
                    fontSize: 13,
                    color: Color(0xFFA2A8B3),
                  ),
                );
              }),
          const Spacer(),
          StreamBuilder<String>(
              initialData: "",
              stream:
                  Stream.periodic(const Duration(milliseconds: 500), (value) {
                return "---";
              }),
              builder: (context, AsyncSnapshot<String> snapshot) {
                return Offstage(
                  offstage: false,
                  child: InkWell(
                    splashColor: Colors.transparent,
                    highlightColor: Colors.transparent,
                    onTap: () {},
                    child: const SizedBox(
                      height: 24,
                      child: Row(
                        children: [
                          Text(
                            "回到顶部",
                            style: TextStyle(
                              fontSize: 13,
                              color: Color(0xFFFE7241),
                            ),
                          ),
                          SizedBox(
                            width: 5,
                          ),
                          Icon(
                            Icons.toc_outlined,
                            size: 20,
                          ),
                          SizedBox(
                            width: 18,
                          )
                        ],
                      ),
                    ),
                  ),
                );
              })
        ],
      ),
    );
  }
}
